package training_camp.day5.leetcode242;

import java.util.HashMap;

class Solution {
    public boolean isAnagram(String s, String t) {
        HashMap<Character, Integer> sMap = new HashMap<>();
        HashMap<Character, Integer> tMap = new HashMap<>();
        char[] sCharArray = s.toCharArray();
        char[] tCharArray = t.toCharArray();
        for (char c : sCharArray) {
            sMap.put(c, sMap.getOrDefault(c, 0) + 1);
        }
        for (char c : tCharArray) {
            if (!sMap.containsKey(c)){
                return false;
            }
            sMap.put(c, sMap.get(c)-1);
            if (sMap.get(c)==0){
                sMap.remove(c);
            }
        }
        if (sMap.size()>0){
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        boolean b = solution.isAnagram("anagram", "nagaram");
        System.out.println(b);
    }
}